import axios from "axios";
import apis from "../../http/apis"
export default {
    namespaced: true,
    state: {
        data:{
            //保存用户登录信息没登录时是个空对象
            user:{}
        }
    },
    mutations: {
        //登录时修改登录用户的信息
        userSave(state,data){
            state.user=data.data;
           
        }
    },
    actions: {
        //user参数是登录时传入的账号，密码，身份
        async login(context,user){
          
            const data = await apis.login.userLogin(user);
           
            if(data.data.status){
            
                localStorage.token = data.data.token;
                context.commit('userSave',data.data);
              
               localStorage.setItem("loginUser",JSON.stringify(data.data.data))
                return 1
            }else{
                return 0
            }
        } 
    },
}